<?php
namespace app\model;
use app\BaseModel;
use think\model\concern\SoftDelete;
use app\model\DemoRadio;
use app\model\DemoSelect;
use app\model\DemoSelectmany;
use app\model\Checkbox;

class Demo extends BaseModel
{

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';
    protected $hidden = ['update_time','delete_time','sort','status'];



    public function searchRadioIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('radio_id','=',$value);
        }
    }
    public function searchRadiotextIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('radiotext_id','=',$value);
        }
    }
    public function searchSelectIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('select_id','=',$value);
        }
    }
    public function searchSelecttextIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('selecttext_id','=',$value);
        }
    }
    public function searchSelectManyIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->whereFindInSet('select_many_id',$value);
        }
    }
    public function searchCheckboxIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->whereFindInSet('checkbox_id',$value);
        }
    }



    protected function setRadioIdAttr($value,$data){ //当前字段的修改器
         $this->set('radio_title',DemoRadio::where('id',$value)->value('title'));
         return $value;
    }
    protected function setRadiotextIdAttr($value,$data){ //当前字段的修改器
         $status = [1=>'R1',2=>'R2',3=>'R3'];
         $this->set('radiotext_title',$status[$data['radiotext_id']]);
         return $value;
    }
    protected function setSelectIdAttr($value,$data){ //当前字段的修改器
         $this->set('select_title',DemoSelect::where('id',$value)->value('title'));
         return $value;
    }
    protected function setSelecttextIdAttr($value,$data){ //当前字段的修改器
         $status = [1=>'S1',2=>'S2',3=>'S3',4=>'S4'];
         $this->set('selecttext_title',$status[$data['selecttext_id']]);
         return $value;
    }
    protected function setSelectManyIdAttr($value,$data){ //当前字段的修改器
         $title = DemoSelectmany::where('id','in',$value)->orderField('id',$value,'asc')->column('title');
         $checkbox_title = implode(',',$title);
         $this->set('select_many_title', $checkbox_title);
         return implode(',',$value);
    }
    protected function setCheckboxIdAttr($value,$data){ //当前字段的修改器
         $title = Checkbox::where('id','in',$value)->orderField('id',$value,'asc')->column('title');
         $checkbox_title = implode(',',$title);
         $this->set('checkbox_title', $checkbox_title);
         return implode(',',$value);
    }





}